<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit"/>
  <meta name="force-rendering" content="webkit"/>
  <!-- import CSS -->
  <link rel="stylesheet" href="../js/3rd/elementUi/index.css">
  <link rel="stylesheet" href="../css/pc.css">
  <script src="../js/3rd/elementUi/vue.js"></script>
  <script src="../js/3rd/jquery-3.1.1.min.js"></script>
</head>
<body>
  <div id="userLists" class="user-lists" style="display:none">
    
	<el-container>
	  <el-aside class="sider-bar" id="siderbar">
      <div class="logo"><img src="../image/logo.jpg">来赚吧管理后台</div> 
	    <tp-siderbar title="发布项目"></tp-siderbar>
	  </el-aside>
    <el-main>
	  <div class="right-content">
      <el-breadcrumb separator-class="el-icon-arrow-right" class="bread-bd">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>分红列表</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button type="primary" round @click="dialogFormVisible=true" style="margin: 20px;float: right;">开始分红</el-button>
      </div>
      <template>
        <el-table
          :data="bonusList"
          stripe
          style="width: 100%">
          <el-table-column
            prop="id"
            label="编号"
            width="180">
          </el-table-column>
          <el-table-column
            prop="title"
            label="名称"
            width="180">
          </el-table-column>
          <el-table-column
            prop="beginTime"
            label="开始时间">
          </el-table-column>
          <el-table-column
            prop="endTime"
            label="结束时间">      
          </el-table-column>
          <el-table-column
            prop="money"
            label="金额">      
          </el-table-column>
          <!-- <el-table-column fixed="right" label="操作">
           <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleCheckCrowFunding(scope.$index, scope.row)">审核</el-button>              
            </template>
          </el-table-column>  -->
        </el-table>
      </template>

      
      <div class="clearfix"></div>
    </div>  
   </el-main>  
	</el-container>
  <el-dialog title="分红" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="活动名称" :label-width="formLabelWidth">
        <el-input v-model="form.title" auto-complete="off"></el-input>
      </el-form-item>
	  <el-form-item label="分红金额" :label-width="formLabelWidth">
	    <el-input v-model="form.money" type="number" auto-complete="off"></el-input>
	  </el-form-item>
      <div class="block">
        <span class="demonstration" style="margin-left: 41px;padding: 0 10px;">分红期限</span>
        <el-date-picker
          v-model="value6"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitHandle">确 定</el-button>
    </div>
  </el-dialog>


</body>


  <!-- import JavaScript -->
  <script src="../js/3rd/elementUi/index.js"></script>
  <script src="../js/js/admin_siderbar.js"></script>
  <script src="../js/js/common.js"></script>
  <script>
   var token=getCookie("userToken");
   var userId=getCookie("userId");
   if(!token||!userId){
      window.location.href = "/admin/login.html";
   }
  

    new Vue({
      el: '#userLists',
      data: {
        bonusList:[],
        telephoneNum:'',
        selectRowContent:'',
        dialogFormVisible:false,
        isDoingSubmitHandle:false,
		isDoingFetch:false,
        selectIndex:null,
        formLabelWidth: '120px',
        currentImageUrl:'',
        form: {
          client: 3,
          beginTime: '',
          endTime: '',
          title: '',
          money: '',
          token: '',
          userId: ''
        },
        value6:''
      },
      created:function(){
         this.fetchList()
         $("#userLists").show();
      },
      methods:{
		    fetchList:function(){
				if(this.isDoingFetch){
					return
				}
				this.isDoingFetch=true;
				var getUsersUrl="/stockPeriod/getStockInList";
				var data={
				          token: token,
				          userId: parseInt(userId),
				          client: 3,
				}
				pushData(getUsersUrl,data,function(res){
				    console.log(res)
					this.isDoingFetch=false;
					if(res.errorCode=="008"){
					  window.location.href = "/admin/login.html";
					}
				    if(res.state){
				     this.bonusList=res.data.stockPeriodList;
				     this.filterBonusList();  
				   }else{
				     alert(res.message)
				   }
				}.bind(this));
			},
            handleCheckCrowFunding:function(index,row){
              this.dialogFormVisible=true;
              this.selectRowContent=row;
              this.selectIndex=index;              
            },
            submitHandle:function(){
              if(this.isDoingSubmitHandle){
                return ;
              }
              this.isDoingSubmitHandle=true;
              console.log(this.value6); 
			  var beginTime=this.formatDay(this.value6[0]);
			  var endTime=this.formatDay(this.value6[1])
			  this.form.beginTime=beginTime
			  this.form.endTime=endTime
			  this.form.token=token
			  this.form.userId=parseInt(userId)
              var data=this.form;
			  
              var url="/stockPeriod/saveStockPeriod ";
              pushData(url,data,function(res){
                if(res.errorCode=="008"){
                   window.location.href = "/admin/login.html";
                }
                this.isDoingSubmitHandle=false;
                if(res.state){                                  
                  this.dialogFormVisible=false;
				  this.fetchList()
                }else{
                  alert(res.message)
                }
              }.bind(this))
            },
            filterBonusList:function(){
              for(var i=0;i<this.bonusList.length;i++){
                     this.bonusList[i].beginTime=formatDate(this.bonusList[i].beginTime)
					 this.bonusList[i].endTime=formatDate(this.bonusList[i].endTime)
                   }
            },
			formatDay:function(standardDate){
				var standardDay = standardDate.getTime(standardDate)
				var year = standardDate.getFullYear();
				var month= standardDate.getMonth()+1;
				var day = standardDate.getDate();
				// var hour = standardDate.getHours();
				// var minute = standardDate.getMinutes();
				// var second = standardDate.getSeconds();
                var formatting = year+'-'+month+'-'+day;
				return formatting
			}

        }

      
    })
  </script>
</html>